﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NetworkTreeSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += (sender, args) => InitTree();
        }

        private void InitTree()
        {
            Item root = new Item() { Text = "Root" };
            this.AddItem(root);

            Tree.DataContext = root;
            Tree.ItemsSource = root;
            Tree.ExpandAll();
        }

        private int maxDepth = 4;
        private void AddItem(Item parent, int depth=0)
        {
            depth = depth + 1;
            for (int i = 0; i < 5; i++)
            {
                var child = new Item() { Text = depth + " My Child " + i };
                parent.SubNodes.Add(child);
                if (depth <= maxDepth)
                    this.AddItem(child, depth);
            }

        }
    }
}
